<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP
           , NoImplicitPrelude
           , MagicHash
           , UnboxedTuples
  #-}</span><span>
</span><span id="line-7"></span><span class="hs-pragma">{-# OPTIONS_HADDOCK not-home #-}</span><span>
</span><span id="line-8"></span><span>
</span><span id="line-9"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Module      :  GHC.Conc.IO</span><span>
</span><span id="line-12"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow, 1994-2002</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- License     :  see libraries/base/LICENSE</span><span>
</span><span id="line-14"></span><span class="hs-comment">--</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Maintainer  :  cvs-ghc@haskell.org</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- Stability   :  internal</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- Portability :  non-portable (GHC extensions)</span><span>
</span><span id="line-18"></span><span class="hs-comment">--</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- Basic concurrency stuff.</span><span>
</span><span id="line-20"></span><span class="hs-comment">--</span><span>
</span><span id="line-21"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-22"></span><span>
</span><span id="line-23"></span><span class="hs-comment">-- No: #hide, because bits of this module are exposed by the stm package.</span><span>
</span><span id="line-24"></span><span class="hs-comment">-- However, we don't want this module to be the home location for the</span><span>
</span><span id="line-25"></span><span class="hs-comment">-- bits it exports, we'd rather have Control.Concurrent and the other</span><span>
</span><span id="line-26"></span><span class="hs-comment">-- higher level modules be the home.  Hence: #not-home</span><span>
</span><span id="line-27"></span><span>
</span><span id="line-28"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Conc.IO</span><span>
</span><span id="line-29"></span><span>        </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Conc.IO.html#ensureIOManagerIsRunning"><span class="hs-identifier">ensureIOManagerIsRunning</span></a></span><span>
</span><span id="line-30"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.IO.html#ioManagerCapabilitiesChanged"><span class="hs-identifier">ioManagerCapabilitiesChanged</span></a></span><span>
</span><span id="line-31"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.IO.html#interruptIOManager"><span class="hs-identifier">interruptIOManager</span></a></span><span>
</span><span id="line-32"></span><span>
</span><span id="line-33"></span><span>        </span><span class="annot"><span class="hs-comment">-- * Waiting</span></span><span>
</span><span id="line-34"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.IO.html#threadDelay"><span class="hs-identifier">threadDelay</span></a></span><span>
</span><span id="line-35"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.IO.html#registerDelay"><span class="hs-identifier">registerDelay</span></a></span><span>
</span><span id="line-36"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.IO.html#threadWaitRead"><span class="hs-identifier">threadWaitRead</span></a></span><span>
</span><span id="line-37"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.IO.html#threadWaitWrite"><span class="hs-identifier">threadWaitWrite</span></a></span><span>
</span><span id="line-38"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.IO.html#threadWaitReadSTM"><span class="hs-identifier">threadWaitReadSTM</span></a></span><span>
</span><span id="line-39"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.IO.html#threadWaitWriteSTM"><span class="hs-identifier">threadWaitWriteSTM</span></a></span><span>
</span><span id="line-40"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.IO.html#closeFdWith"><span class="hs-identifier">closeFdWith</span></a></span><span class="hs-cpp">

#if defined(mingw32_HOST_OS)
</span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Windows.html#asyncRead"><span class="hs-identifier">asyncRead</span></a></span><span>
</span><span id="line-44"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Windows.html#asyncWrite"><span class="hs-identifier">asyncWrite</span></a></span><span>
</span><span id="line-45"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Windows.html#asyncDoProc"><span class="hs-identifier">asyncDoProc</span></a></span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Windows.html#asyncReadBA"><span class="hs-identifier">asyncReadBA</span></a></span><span>
</span><span id="line-48"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Windows.html#asyncWriteBA"><span class="hs-identifier">asyncWriteBA</span></a></span><span>
</span><span id="line-49"></span><span>
</span><span id="line-50"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ConsoleEvent.html#ConsoleEvent"><span class="hs-identifier">ConsoleEvent</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span>
</span><span id="line-51"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ConsoleEvent.html#win32ConsoleHandler"><span class="hs-identifier">win32ConsoleHandler</span></a></span><span>
</span><span id="line-52"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ConsoleEvent.html#toWin32ConsoleEvent"><span class="hs-identifier">toWin32ConsoleEvent</span></a></span><span class="hs-cpp">
#endif
</span><span>        </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-55"></span><span>
</span><span id="line-56"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.html"><span class="hs-identifier">Foreign</span></a></span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-58"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html"><span class="hs-identifier">GHC.Conc.Sync</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Sync</span></span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier">fromIntegral</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-60"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Posix.Types.html"><span class="hs-identifier">System.Posix.Types</span></a></span><span class="hs-cpp">

#if defined(mingw32_HOST_OS)
</span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.Conc.Windows.html"><span class="hs-identifier">GHC.Conc.Windows</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Windows</span></span><span>
</span><span id="line-64"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.SubSystem.html"><span class="hs-identifier">GHC.IO.SubSystem</span></a></span><span>
</span><span id="line-65"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Conc.Windows.html"><span class="hs-identifier">GHC.Conc.Windows</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Windows.html#asyncRead"><span class="hs-identifier">asyncRead</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Windows.html#asyncWrite"><span class="hs-identifier">asyncWrite</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Windows.html#asyncDoProc"><span class="hs-identifier">asyncDoProc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Conc.Windows.html#asyncReadBA"><span class="hs-identifier">asyncReadBA</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-66"></span><span>                         </span><span class="annot"><a href="GHC.Conc.Windows.html#asyncWriteBA"><span class="hs-identifier">asyncWriteBA</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ConsoleEvent.html#ConsoleEvent"><span class="hs-identifier">ConsoleEvent</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Event.Windows.ConsoleEvent.html#win32ConsoleHandler"><span class="hs-identifier">win32ConsoleHandler</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-67"></span><span>                         </span><span class="annot"><a href="GHC.Event.Windows.ConsoleEvent.html#toWin32ConsoleEvent"><span class="hs-identifier">toWin32ConsoleEvent</span></a></span><span class="hs-special">)</span><span class="hs-cpp">
#else
</span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="hs-identifier">GHC.Event.Thread</span><span> </span><span class="hs-keyword">as</span><span> </span><span class="hs-identifier">Event</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-72"></span><span class="annot"><a href="GHC.Conc.IO.html#ensureIOManagerIsRunning"><span class="hs-identifier hs-type">ensureIOManagerIsRunning</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">
#if !defined(mingw32_HOST_OS)
</span><span class="hs-identifier">ensureIOManagerIsRunning</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Event.ensureIOManagerIsRunning</span><span class="hs-cpp">
#else
</span><span id="ensureIOManagerIsRunning"><span class="annot"><span class="annottext">ensureIOManagerIsRunning :: IO ()
</span><a href="GHC.Conc.IO.html#ensureIOManagerIsRunning"><span class="hs-identifier hs-var hs-var">ensureIOManagerIsRunning</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="GHC.Conc.Windows.html#ensureIOManagerIsRunning"><span class="hs-identifier hs-var">Windows.ensureIOManagerIsRunning</span></a></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-79"></span><span class="hs-comment">-- | Interrupts the current wait of the I/O manager if it is currently blocked.</span><span>
</span><span id="line-80"></span><span class="hs-comment">-- This instructs it to re-read how much it should wait and to process any</span><span>
</span><span id="line-81"></span><span class="hs-comment">-- pending events.</span><span>
</span><span id="line-82"></span><span class="hs-comment">-- @since 4.15</span><span>
</span><span id="line-83"></span><span class="annot"><a href="GHC.Conc.IO.html#interruptIOManager"><span class="hs-identifier hs-type">interruptIOManager</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">
#if !defined(mingw32_HOST_OS)
</span><span class="hs-identifier">interruptIOManager</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">return</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">
#else
</span><span id="interruptIOManager"><span class="annot"><span class="annottext">interruptIOManager :: IO ()
</span><a href="GHC.Conc.IO.html#interruptIOManager"><span class="hs-identifier hs-var hs-var">interruptIOManager</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="GHC.Conc.Windows.html#interruptIOManager"><span class="hs-identifier hs-var">Windows.interruptIOManager</span></a></span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-90"></span><span class="annot"><a href="GHC.Conc.IO.html#ioManagerCapabilitiesChanged"><span class="hs-identifier hs-type">ioManagerCapabilitiesChanged</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">
#if !defined(mingw32_HOST_OS)
</span><span class="hs-identifier">ioManagerCapabilitiesChanged</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Event.ioManagerCapabilitiesChanged</span><span class="hs-cpp">
#else
</span><span id="ioManagerCapabilitiesChanged"><span class="annot"><span class="annottext">ioManagerCapabilitiesChanged :: IO ()
</span><a href="GHC.Conc.IO.html#ioManagerCapabilitiesChanged"><span class="hs-identifier hs-var hs-var">ioManagerCapabilitiesChanged</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>
</span><span id="line-97"></span><span class="hs-comment">-- | Block the current thread until data is available to read on the</span><span>
</span><span id="line-98"></span><span class="hs-comment">-- given file descriptor (GHC only).</span><span>
</span><span id="line-99"></span><span class="hs-comment">--</span><span>
</span><span id="line-100"></span><span class="hs-comment">-- This will throw an 'Prelude.IOError' if the file descriptor was closed</span><span>
</span><span id="line-101"></span><span class="hs-comment">-- while this thread was blocked.  To safely close a file descriptor</span><span>
</span><span id="line-102"></span><span class="hs-comment">-- that has been used with 'threadWaitRead', use 'closeFdWith'.</span><span>
</span><span id="line-103"></span><span class="annot"><a href="GHC.Conc.IO.html#threadWaitRead"><span class="hs-identifier hs-type">threadWaitRead</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="System.Posix.Types.html#Fd"><span class="hs-identifier hs-type">Fd</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-104"></span><span id="threadWaitRead"><span class="annot"><span class="annottext">threadWaitRead :: Fd -&gt; IO ()
</span><a href="GHC.Conc.IO.html#threadWaitRead"><span class="hs-identifier hs-var hs-var">threadWaitRead</span></a></span></span><span> </span><span id="local-6989586621679553686"><span class="annot"><span class="annottext">Fd
</span><a href="#local-6989586621679553686"><span class="hs-identifier hs-var">fd</span></a></span></span><span class="hs-cpp">
#if !defined(mingw32_HOST_OS)
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">threaded</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Event.threadWaitRead</span><span> </span><span class="hs-identifier">fd</span><span class="hs-cpp">
#endif
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ())
-&gt; (State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679553685"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679553685"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-109"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Fd -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Fd
</span><a href="#local-6989586621679553686"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679553684"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679553684"><span class="hs-identifier hs-var">fd#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-110"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; State# RealWorld -&gt; State# RealWorld
forall d. Int# -&gt; State# d -&gt; State# d
</span><a href="../../ghc-prim/src/GHC.Prim.html#waitRead%23"><span class="hs-identifier hs-var">waitRead#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679553684"><span class="hs-identifier hs-var">fd#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679553685"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621679553683"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679553683"><span class="hs-identifier hs-var">s'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679553683"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-111"></span><span>        </span><span class="hs-special">}</span><span class="hs-special">}</span><span>
</span><span id="line-112"></span><span>
</span><span id="line-113"></span><span class="hs-comment">-- | Block the current thread until data can be written to the</span><span>
</span><span id="line-114"></span><span class="hs-comment">-- given file descriptor (GHC only).</span><span>
</span><span id="line-115"></span><span class="hs-comment">--</span><span>
</span><span id="line-116"></span><span class="hs-comment">-- This will throw an 'Prelude.IOError' if the file descriptor was closed</span><span>
</span><span id="line-117"></span><span class="hs-comment">-- while this thread was blocked.  To safely close a file descriptor</span><span>
</span><span id="line-118"></span><span class="hs-comment">-- that has been used with 'threadWaitWrite', use 'closeFdWith'.</span><span>
</span><span id="line-119"></span><span class="annot"><a href="GHC.Conc.IO.html#threadWaitWrite"><span class="hs-identifier hs-type">threadWaitWrite</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="System.Posix.Types.html#Fd"><span class="hs-identifier hs-type">Fd</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-120"></span><span id="threadWaitWrite"><span class="annot"><span class="annottext">threadWaitWrite :: Fd -&gt; IO ()
</span><a href="GHC.Conc.IO.html#threadWaitWrite"><span class="hs-identifier hs-var hs-var">threadWaitWrite</span></a></span></span><span> </span><span id="local-6989586621679553682"><span class="annot"><span class="annottext">Fd
</span><a href="#local-6989586621679553682"><span class="hs-identifier hs-var">fd</span></a></span></span><span class="hs-cpp">
#if !defined(mingw32_HOST_OS)
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">threaded</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Event.threadWaitWrite</span><span> </span><span class="hs-identifier">fd</span><span class="hs-cpp">
#endif
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ())
-&gt; (State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679553681"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679553681"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-125"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Fd -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Fd
</span><a href="#local-6989586621679553682"><span class="hs-identifier hs-var">fd</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679553680"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679553680"><span class="hs-identifier hs-var">fd#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-126"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; State# RealWorld -&gt; State# RealWorld
forall d. Int# -&gt; State# d -&gt; State# d
</span><a href="../../ghc-prim/src/GHC.Prim.html#waitWrite%23"><span class="hs-identifier hs-var">waitWrite#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679553680"><span class="hs-identifier hs-var">fd#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679553681"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621679553679"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679553679"><span class="hs-identifier hs-var">s'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679553679"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-127"></span><span>        </span><span class="hs-special">}</span><span class="hs-special">}</span><span>
</span><span id="line-128"></span><span>
</span><span id="line-129"></span><span class="hs-comment">-- | Returns an STM action that can be used to wait for data</span><span>
</span><span id="line-130"></span><span class="hs-comment">-- to read from a file descriptor. The second returned value</span><span>
</span><span id="line-131"></span><span class="hs-comment">-- is an IO action that can be used to deregister interest</span><span>
</span><span id="line-132"></span><span class="hs-comment">-- in the file descriptor.</span><span>
</span><span id="line-133"></span><span class="annot"><a href="GHC.Conc.IO.html#threadWaitReadSTM"><span class="hs-identifier hs-type">threadWaitReadSTM</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="System.Posix.Types.html#Fd"><span class="hs-identifier hs-type">Fd</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">Sync.STM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-134"></span><span id="threadWaitReadSTM"><span class="annot"><span class="annottext">threadWaitReadSTM :: Fd -&gt; IO (STM (), IO ())
</span><a href="GHC.Conc.IO.html#threadWaitReadSTM"><span class="hs-identifier hs-var hs-var">threadWaitReadSTM</span></a></span></span><span> </span><span id="local-6989586621679553678"><span class="annot"><span class="annottext">Fd
</span><a href="#local-6989586621679553678"><span class="hs-identifier hs-var">fd</span></a></span></span><span class="hs-cpp">
#if !defined(mingw32_HOST_OS)
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">threaded</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Event.threadWaitReadSTM</span><span> </span><span class="hs-identifier">fd</span><span class="hs-cpp">
#endif
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-139"></span><span>      </span><span id="local-6989586621679553677"><span class="annot"><span class="annottext">TVar Bool
</span><a href="#local-6989586621679553677"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO (TVar Bool)
forall a. a -&gt; IO (TVar a)
</span><a href="GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier hs-var">Sync.newTVarIO</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-140"></span><span>      </span><span id="local-6989586621679553675"><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679553675"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO ThreadId
</span><a href="GHC.Conc.Sync.html#forkIO"><span class="hs-identifier hs-var">Sync.forkIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ThreadId) -&gt; IO () -&gt; IO ThreadId
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-141"></span><span>        </span><span class="annot"><span class="annottext">Fd -&gt; IO ()
</span><a href="GHC.Conc.IO.html#threadWaitRead"><span class="hs-identifier hs-var">threadWaitRead</span></a></span><span> </span><span class="annot"><span class="annottext">Fd
</span><a href="#local-6989586621679553678"><span class="hs-identifier hs-var">fd</span></a></span><span>
</span><span id="line-142"></span><span>        </span><span class="annot"><span class="annottext">STM () -&gt; IO ()
forall a. STM a -&gt; IO a
</span><a href="GHC.Conc.Sync.html#atomically"><span class="hs-identifier hs-var">Sync.atomically</span></a></span><span> </span><span class="annot"><span class="annottext">(STM () -&gt; IO ()) -&gt; STM () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Bool -&gt; Bool -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">Sync.writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Bool
</span><a href="#local-6989586621679553677"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-143"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679553668"><span class="annot"><span class="annottext">waitAction :: STM ()
</span><a href="#local-6989586621679553668"><span class="hs-identifier hs-var hs-var">waitAction</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679553667"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679553667"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar Bool -&gt; STM Bool
forall a. TVar a -&gt; STM a
</span><a href="GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">Sync.readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Bool
</span><a href="#local-6989586621679553677"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-144"></span><span>                          </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679553667"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">() -&gt; STM ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">STM ()
forall a. STM a
</span><a href="GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-145"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679553664"><span class="annot"><span class="annottext">killAction :: IO ()
</span><a href="#local-6989586621679553664"><span class="hs-identifier hs-var hs-var">killAction</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ThreadId -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#killThread"><span class="hs-identifier hs-var">Sync.killThread</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679553675"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-146"></span><span>      </span><span class="annot"><span class="annottext">(STM (), IO ()) -&gt; IO (STM (), IO ())
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">STM ()
</span><a href="#local-6989586621679553668"><span class="hs-identifier hs-var">waitAction</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679553664"><span class="hs-identifier hs-var">killAction</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-147"></span><span>
</span><span id="line-148"></span><span class="hs-comment">-- | Returns an STM action that can be used to wait until data</span><span>
</span><span id="line-149"></span><span class="hs-comment">-- can be written to a file descriptor. The second returned value</span><span>
</span><span id="line-150"></span><span class="hs-comment">-- is an IO action that can be used to deregister interest</span><span>
</span><span id="line-151"></span><span class="hs-comment">-- in the file descriptor.</span><span>
</span><span id="line-152"></span><span class="annot"><a href="GHC.Conc.IO.html#threadWaitWriteSTM"><span class="hs-identifier hs-type">threadWaitWriteSTM</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="System.Posix.Types.html#Fd"><span class="hs-identifier hs-type">Fd</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#STM"><span class="hs-identifier hs-type">Sync.STM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-153"></span><span id="threadWaitWriteSTM"><span class="annot"><span class="annottext">threadWaitWriteSTM :: Fd -&gt; IO (STM (), IO ())
</span><a href="GHC.Conc.IO.html#threadWaitWriteSTM"><span class="hs-identifier hs-var hs-var">threadWaitWriteSTM</span></a></span></span><span> </span><span id="local-6989586621679553662"><span class="annot"><span class="annottext">Fd
</span><a href="#local-6989586621679553662"><span class="hs-identifier hs-var">fd</span></a></span></span><span class="hs-cpp">
#if !defined(mingw32_HOST_OS)
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">threaded</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Event.threadWaitWriteSTM</span><span> </span><span class="hs-identifier">fd</span><span class="hs-cpp">
#endif
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-158"></span><span>      </span><span id="local-6989586621679553661"><span class="annot"><span class="annottext">TVar Bool
</span><a href="#local-6989586621679553661"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO (TVar Bool)
forall a. a -&gt; IO (TVar a)
</span><a href="GHC.Conc.Sync.html#newTVarIO"><span class="hs-identifier hs-var">Sync.newTVarIO</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-159"></span><span>      </span><span id="local-6989586621679553660"><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679553660"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO ThreadId
</span><a href="GHC.Conc.Sync.html#forkIO"><span class="hs-identifier hs-var">Sync.forkIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ThreadId) -&gt; IO () -&gt; IO ThreadId
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-160"></span><span>        </span><span class="annot"><span class="annottext">Fd -&gt; IO ()
</span><a href="GHC.Conc.IO.html#threadWaitWrite"><span class="hs-identifier hs-var">threadWaitWrite</span></a></span><span> </span><span class="annot"><span class="annottext">Fd
</span><a href="#local-6989586621679553662"><span class="hs-identifier hs-var">fd</span></a></span><span>
</span><span id="line-161"></span><span>        </span><span class="annot"><span class="annottext">STM () -&gt; IO ()
forall a. STM a -&gt; IO a
</span><a href="GHC.Conc.Sync.html#atomically"><span class="hs-identifier hs-var">Sync.atomically</span></a></span><span> </span><span class="annot"><span class="annottext">(STM () -&gt; IO ()) -&gt; STM () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Bool -&gt; Bool -&gt; STM ()
forall a. TVar a -&gt; a -&gt; STM ()
</span><a href="GHC.Conc.Sync.html#writeTVar"><span class="hs-identifier hs-var">Sync.writeTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Bool
</span><a href="#local-6989586621679553661"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-162"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679553657"><span class="annot"><span class="annottext">waitAction :: STM ()
</span><a href="#local-6989586621679553657"><span class="hs-identifier hs-var hs-var">waitAction</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679553656"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679553656"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TVar Bool -&gt; STM Bool
forall a. TVar a -&gt; STM a
</span><a href="GHC.Conc.Sync.html#readTVar"><span class="hs-identifier hs-var">Sync.readTVar</span></a></span><span> </span><span class="annot"><span class="annottext">TVar Bool
</span><a href="#local-6989586621679553661"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-163"></span><span>                          </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679553656"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">() -&gt; STM ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">STM ()
forall a. STM a
</span><a href="GHC.Conc.Sync.html#retry"><span class="hs-identifier hs-var">retry</span></a></span><span>
</span><span id="line-164"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679553655"><span class="annot"><span class="annottext">killAction :: IO ()
</span><a href="#local-6989586621679553655"><span class="hs-identifier hs-var hs-var">killAction</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ThreadId -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#killThread"><span class="hs-identifier hs-var">Sync.killThread</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679553660"><span class="hs-identifier hs-var">t</span></a></span><span>
</span><span id="line-165"></span><span>      </span><span class="annot"><span class="annottext">(STM (), IO ()) -&gt; IO (STM (), IO ())
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">STM ()
</span><a href="#local-6989586621679553657"><span class="hs-identifier hs-var">waitAction</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679553655"><span class="hs-identifier hs-var">killAction</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-166"></span><span>
</span><span id="line-167"></span><span class="hs-comment">-- | Close a file descriptor in a concurrency-safe way (GHC only).  If</span><span>
</span><span id="line-168"></span><span class="hs-comment">-- you are using 'threadWaitRead' or 'threadWaitWrite' to perform</span><span>
</span><span id="line-169"></span><span class="hs-comment">-- blocking I\/O, you /must/ use this function to close file</span><span>
</span><span id="line-170"></span><span class="hs-comment">-- descriptors, or blocked threads may not be woken.</span><span>
</span><span id="line-171"></span><span class="hs-comment">--</span><span>
</span><span id="line-172"></span><span class="hs-comment">-- Any threads that are blocked on the file descriptor via</span><span>
</span><span id="line-173"></span><span class="hs-comment">-- 'threadWaitRead' or 'threadWaitWrite' will be unblocked by having</span><span>
</span><span id="line-174"></span><span class="hs-comment">-- IO exceptions thrown.</span><span>
</span><span id="line-175"></span><span class="annot"><a href="GHC.Conc.IO.html#closeFdWith"><span class="hs-identifier hs-type">closeFdWith</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="System.Posix.Types.html#Fd"><span class="hs-identifier hs-type">Fd</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- ^ Low-level action that performs the real close.</span><span>
</span><span id="line-176"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="System.Posix.Types.html#Fd"><span class="hs-identifier hs-type">Fd</span></a></span><span>            </span><span class="hs-comment">-- ^ File descriptor to close.</span><span>
</span><span id="line-177"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-178"></span><span id="closeFdWith"><span class="annot"><span class="annottext">closeFdWith :: (Fd -&gt; IO ()) -&gt; Fd -&gt; IO ()
</span><a href="GHC.Conc.IO.html#closeFdWith"><span class="hs-identifier hs-var hs-var">closeFdWith</span></a></span></span><span> </span><span id="local-6989586621679553654"><span class="annot"><span class="annottext">Fd -&gt; IO ()
</span><a href="#local-6989586621679553654"><span class="hs-identifier hs-var">close</span></a></span></span><span> </span><span id="local-6989586621679553653"><span class="annot"><span class="annottext">Fd
</span><a href="#local-6989586621679553653"><span class="hs-identifier hs-var">fd</span></a></span></span><span class="hs-cpp">
#if !defined(mingw32_HOST_OS)
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">threaded</span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Event.closeFdWith</span><span> </span><span class="hs-identifier">close</span><span> </span><span class="hs-identifier">fd</span><span class="hs-cpp">
#endif
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Fd -&gt; IO ()
</span><a href="#local-6989586621679553654"><span class="hs-identifier hs-var">close</span></a></span><span> </span><span class="annot"><span class="annottext">Fd
</span><a href="#local-6989586621679553653"><span class="hs-identifier hs-var">fd</span></a></span><span>
</span><span id="line-183"></span><span>
</span><span id="line-184"></span><span class="hs-comment">-- | Suspends the current thread for a given number of microseconds</span><span>
</span><span id="line-185"></span><span class="hs-comment">-- (GHC only).</span><span>
</span><span id="line-186"></span><span class="hs-comment">--</span><span>
</span><span id="line-187"></span><span class="hs-comment">-- There is no guarantee that the thread will be rescheduled promptly</span><span>
</span><span id="line-188"></span><span class="hs-comment">-- when the delay has expired, but the thread will never continue to</span><span>
</span><span id="line-189"></span><span class="hs-comment">-- run /earlier/ than specified.</span><span>
</span><span id="line-190"></span><span class="hs-comment">--</span><span>
</span><span id="line-191"></span><span class="annot"><a href="GHC.Conc.IO.html#threadDelay"><span class="hs-identifier hs-type">threadDelay</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-192"></span><span id="threadDelay"><span class="annot"><span class="annottext">threadDelay :: Int -&gt; IO ()
</span><a href="GHC.Conc.IO.html#threadDelay"><span class="hs-identifier hs-var hs-var">threadDelay</span></a></span></span><span> </span><span id="local-6989586621679553652"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679553652"><span class="hs-identifier hs-var">time</span></a></span></span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.IO.SubSystem.html#isWindowsNativeIO"><span class="hs-identifier hs-var">isWindowsNativeIO</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO ()
</span><a href="GHC.Conc.Windows.html#threadDelay"><span class="hs-identifier hs-var">Windows.threadDelay</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679553652"><span class="hs-identifier hs-var">time</span></a></span><span>
</span><span id="line-195"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Conc.IO.html#threaded"><span class="hs-identifier hs-var">threaded</span></a></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO ()
</span><a href="GHC.Conc.Windows.html#threadDelay"><span class="hs-identifier hs-var">Windows.threadDelay</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679553652"><span class="hs-identifier hs-var">time</span></a></span><span class="hs-cpp">
#else
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">threaded</span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Event.threadDelay</span><span> </span><span class="hs-identifier">time</span><span class="hs-cpp">
#endif
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a. (State# RealWorld -&gt; (# State# RealWorld, a #)) -&gt; IO a
</span><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-var">IO</span></a></span><span> </span><span class="annot"><span class="annottext">((State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ())
-&gt; (State# RealWorld -&gt; (# State# RealWorld, () #)) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679553648"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679553648"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-200"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679553652"><span class="hs-identifier hs-var">time</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span id="local-6989586621679553647"><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679553647"><span class="hs-identifier hs-var">time#</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-201"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int# -&gt; State# RealWorld -&gt; State# RealWorld
forall d. Int# -&gt; State# d -&gt; State# d
</span><a href="../../ghc-prim/src/GHC.Prim.html#delay%23"><span class="hs-identifier hs-var">delay#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><a href="#local-6989586621679553647"><span class="hs-identifier hs-var">time#</span></a></span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679553648"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621679553646"><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679553646"><span class="hs-identifier hs-var">s'</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(#</span><span> </span><span class="annot"><span class="annottext">State# RealWorld
</span><a href="#local-6989586621679553646"><span class="hs-identifier hs-var">s'</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-special">#)</span><span>
</span><span id="line-202"></span><span>        </span><span class="hs-special">}</span><span class="hs-special">}</span><span>
</span><span id="line-203"></span><span>
</span><span id="line-204"></span><span class="hs-comment">-- | Switch the value of returned 'TVar' from initial value 'False' to 'True'</span><span>
</span><span id="line-205"></span><span class="hs-comment">-- after a given number of microseconds. The caveats associated with</span><span>
</span><span id="line-206"></span><span class="hs-comment">-- 'threadDelay' also apply.</span><span>
</span><span id="line-207"></span><span class="hs-comment">--</span><span>
</span><span id="line-208"></span><span class="annot"><a href="GHC.Conc.IO.html#registerDelay"><span class="hs-identifier hs-type">registerDelay</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Conc.Sync.html#TVar"><span class="hs-identifier hs-type">TVar</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-209"></span><span id="registerDelay"><span class="annot"><span class="annottext">registerDelay :: Int -&gt; IO (TVar Bool)
</span><a href="GHC.Conc.IO.html#registerDelay"><span class="hs-identifier hs-var hs-var">registerDelay</span></a></span></span><span> </span><span id="local-6989586621679553645"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679553645"><span class="hs-identifier hs-var">usecs</span></a></span></span><span class="hs-cpp">
#if defined(mingw32_HOST_OS)
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.IO.SubSystem.html#isWindowsNativeIO"><span class="hs-identifier hs-var">isWindowsNativeIO</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO (TVar Bool)
</span><a href="GHC.Conc.Windows.html#registerDelay"><span class="hs-identifier hs-var">Windows.registerDelay</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679553645"><span class="hs-identifier hs-var">usecs</span></a></span><span>
</span><span id="line-212"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Conc.IO.html#threaded"><span class="hs-identifier hs-var">threaded</span></a></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO (TVar Bool)
</span><a href="GHC.Conc.Windows.html#registerDelay"><span class="hs-identifier hs-var">Windows.registerDelay</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679553645"><span class="hs-identifier hs-var">usecs</span></a></span><span class="hs-cpp">
#else
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="hs-identifier">threaded</span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="hs-identifier">Event.registerDelay</span><span> </span><span class="hs-identifier">usecs</span><span class="hs-cpp">
#endif
</span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>         </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Char] -&gt; IO (TVar Bool)
forall a. [Char] -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">[Char]
</span><span class="hs-string">&quot;registerDelay: requires -threaded&quot;</span></span><span>
</span><span id="line-217"></span><span>
</span><span id="line-218"></span><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;rtsSupportsBoundThreads&quot;</span></span><span> </span><span id="threaded"><span class="annot"><a href="GHC.Conc.IO.html#threaded"><span class="hs-identifier hs-var">threaded</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-219"></span></pre></body></html>